﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace FCMS.Mvc
{
    public class SkinViewEngine : RazorViewEngine
    {
        public string SkinName { get; set; }

        public SkinViewEngine()
            : this("default")
        {
        }

        public SkinViewEngine(string skinName)
        {
            SkinName = skinName;
            MasterLocationFormats = new[]{
                string.Format("~/skins/{0}/views/{{1}}/{{0}}.cshtml", SkinName),
                string.Format("~/skins/{0}/views/shared/{{0}}.cshtml", SkinName)
            };

            ViewLocationFormats = new[]{
                string.Format("~/skins/{0}/views/{{1}}/{{0}}.cshtml", SkinName),
                string.Format("~/skins/{0}/views/shared/{{0}}.cshtml", SkinName),
                string.Format("~/skins/default/views/{{1}}/{{0}}.cshtml", SkinName),
                string.Format("~/skins/default/views/shared/{{0}}.cshtml", SkinName),
            };
            PartialViewLocationFormats = ViewLocationFormats;
        }

        protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
        {
            return base.CreatePartialView(controllerContext, partialPath);
        }

        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            return base.CreateView(controllerContext, viewPath, masterPath);
        }
    }
}
